package com.itheima.wechat;

import com.itheima.entity.Result;
import com.itheima.utils.JedisUtil;
import com.itheima.utils.SmsUtil;
import com.itheima.utils.ValidateCodeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/validateCode")
public class ValidateCodeController {

    @Autowired
    JedisUtil jedisUtil;

    @RequestMapping("/send4Order")
    public Result send4Order(String telephone){
        //生成验证码
        Integer code = ValidateCodeUtils.generateValidateCode(4);
        //发送验证码
//        SmsUtil.sendSmsCode(telephone,String.valueOf(code));
        System.out.println("code:" + code);
        //把验证码存入redis（提交预约的时候需要和用户比对）
        jedisUtil.add(telephone + "001",60 * 5 * 100,String.valueOf(code));

        return Result.success("");
    }


    @RequestMapping("/send4Login")
    public Result send4Login(String telephone){
        //生成验证码
        Integer code = ValidateCodeUtils.generateValidateCode(4);
        //发送验证码
//        SmsUtil.sendSmsCode(telephone,String.valueOf(code));
        System.out.println("code:" + code);
        //把验证码存入redis（提交预约的时候需要和用户比对）
        jedisUtil.add(telephone + "002",60 * 5 * 100,String.valueOf(code));

        return Result.success("");
    }

}
